import sim, sim_items, main
from util import *
import random

class SpikedPrefix(sim_items.Prefix):
    """
    "spiked" prefix gives affected weapon a small max damage bonus, increased
    attack energy, and slightly increased weight.
    """
    def __init__(self):
        super(SpikedPrefix, self).__init__(
            "spiked", # name
            # description: (gets tacked onto item description)
            "Some too-enthusiastic smith or tinker has affixed an assortment "
            "of sharp metal spikes to this %(wearable)s."
        )

    def initialize(self, wearable):
        if not isinstance(wearable, sim_items.Weapon):
            raise ValueError('Tried to apply %r to non-weapon item: %r' % (self,
                wearable))

        super(SpikedPrefix, self).initialize(wearable)

        multiplier = 0.05 + 0.1*random.random()
        self.dmgMod = multiplier * wearable.damage
        self.attackEnergyMod = multiplier * wearable.attackEnergy
        self.weightMod = multiplier * wearable.weight

        wearable.damage += self.dmgMod
        wearable.attackEnergy += self.attackEnergyMod
        wearable.weight += self.weightMod

    def remove(self, wearable):
        super(SpikedPrefix, self).remove(wearable)
        wearable.damage -= self.dmgMod
        wearable.attackEnergy -= self.attackEnergyMod
        wearable.weight -= self.weightMod

#========================================
thingClass = SpikedPrefix

